//
//  YYEHotCourseCollectionViewCell.m
//  YuYingEDU
//
//  Created by 胡波 on 2017/12/28.
//  Copyright © 2017年 胡波. All rights reserved.
//

#import "YYEHotCourseCollectionViewCell.h"

@interface YYEHotCourseCollectionViewCell ()

@property (nonatomic,strong) UIImageView *headerIV;
@property (nonatomic,strong) UIImageView *backIV;
@property (nonatomic,strong) UILabel *courseNumLabel;
@property (nonatomic,strong) UILabel *priceLabel;
@property (nonatomic,strong) UILabel *courseNameLabel;
@property (nonatomic,strong) UILabel *teacherLabel;

@end

@implementation YYEHotCourseCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.headerIV = [[UIImageView alloc]init];
//        self.headerIV.backgroundColor = [UIColor redColor];
        self.headerIV.layer.cornerRadius = 5;
        self.headerIV.clipsToBounds = YES;
        [self.contentView addSubview:self.headerIV];
        
        self.backIV = [[UIImageView alloc]init];
        self.backIV.image = [UIImage imageNamed:@"Rectangle"];
        [self.headerIV addSubview:self.backIV];
        
        self.courseNumLabel = [[UILabel alloc]init];
        self.courseNumLabel.textColor = [UIColor whiteColor];
        self.courseNumLabel.font = [UIFont systemFontOfSize:12];
        [self.backIV addSubview:self.courseNumLabel];
        
        self.priceLabel = [[UILabel alloc]init];
        self.priceLabel.textColor = [UIColor whiteColor];
        self.priceLabel.font = [UIFont systemFontOfSize:12];
        self.priceLabel.textAlignment = NSTextAlignmentRight;
        [self.backIV addSubview:self.priceLabel];
        self.priceLabel.hidden = YES;
        
        self.courseNameLabel = [[UILabel alloc]init];
        self.courseNameLabel.textColor = [UIColor blackColor];
        self.courseNameLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.courseNameLabel];
        
        self.teacherLabel = [[UILabel alloc]init];
        self.teacherLabel.textColor = [UIColor blackColor];
        self.teacherLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.teacherLabel];
        
        self.courseNumLabel.text = @"课时 26";
//        self.priceLabel.text = @"￥299.00";
        self.courseNameLabel.text = @"英语-轻松过四级小秘籍";
        self.teacherLabel.text = @"育英高级讲师-程可";
        
    }
    return self;
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    // 98 178 0.55
    [self.headerIV makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(3);
        make.top.equalTo(self.contentView.top).offset(10);
        make.right.equalTo(self.contentView.right).offset(-3);
        make.height.equalTo((self.contentView.bounds.size.width - 6) * 0.55);
    }];
    
    [self.backIV makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.headerIV);
        make.height.equalTo(17);
    }];
    
    [self.courseNumLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backIV.left).offset(4);
        make.bottom.equalTo(self.backIV.bottom);
    }];
    
    [self.priceLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.backIV.right).offset(-4);
        make.bottom.equalTo(self.backIV.bottom);
    }];
    
    [self.courseNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(3);
        make.top.equalTo(self.headerIV.bottom).offset(5);
        make.height.equalTo(17);
    }];
    
    [self.teacherLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(3);
        make.top.equalTo(self.courseNameLabel.bottom).offset(2);
        make.height.equalTo(17);
        make.bottom.equalTo(self.contentView.bottom).offset(-20);
    }];
    
}

- (void)setModel:(YYEHomeCourseModel *)model {
    _model = model;
    
    [self.headerIV sd_setImageWithURL:[NSURL URLWithString:model.img]];
    self.courseNumLabel.text = [NSString stringWithFormat:@"课时%@",model.nums];
//    self.priceLabel.text = [NSString stringWithFormat:@"￥%@",model.price];
    self.courseNameLabel.text = model.title;
    
    if (model.name) {
        model.tname = model.name;
    }
    if (model.role.length) {
        self.teacherLabel.text = [NSString stringWithFormat:@"%@-%@",model.role,model.tname];

    }
    else {
        self.teacherLabel.text = [NSString stringWithFormat:@"%@",model.tname];

    }
    
}

- (void)setCourseModel:(YYECourseModel *)courseModel {
    
    [self.headerIV sd_setImageWithURL:[NSURL URLWithString:courseModel.img]];
    self.courseNumLabel.text = [NSString stringWithFormat:@"课时%@",courseModel.nums];
//    if ([courseModel.priceName isEqualToString:@"付费课"]) {
//        self.priceLabel.text = [NSString stringWithFormat:@"￥%@",courseModel.price];;
//    }else {
//        self.priceLabel.text = courseModel.priceName;
//    }
    self.courseNameLabel.text = courseModel.title;
    if (courseModel.role.length) {
        self.teacherLabel.text = [NSString stringWithFormat:@"%@-%@",courseModel.role,courseModel.tname];
        
    }
    else {
        self.teacherLabel.text = [NSString stringWithFormat:@"%@",courseModel.tname];
        
    }
    
}

// 61 + (screeW/2 - 6) * 0.55

@end
